using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class LaserGeneratorHandler : LightRayHandler {

	public GameObject colorPicker;
	public GameObject colorIcon;
	public GameObject rayGen;
	
	private float pickerActiveTime;
	
	public override void initialize(int id, Vector3 position, float rotation, Color c, bool fixedObj){
		Type = ObjectType.LaserGenerator;
		
		base.initialize(id, position, rotation, c, fixedObj);
		
		if(LevelConstants.editorMode){
			gameObject.layer = LayerMask.NameToLayer("GPObject");	
		}
		
		rayGen.GetComponent<LightRay>().initColor = currentColor;
		colorPicker.GetComponent<ColorPickerHandler>().colorObject(currentColor);
		if(!isFixed && LevelConstants.editorMode){
			colorIcon.SetActive(true);
			colorPicker.SetActive(false);
		}
		if(isFixed){
			colorIcon.SetActive(false);
			colorPicker.SetActive(false);
		}
	}
	
	public override void onClick(){
		if(!isFixed){
			if(colorPicker.activeInHierarchy){
				
				GPObject prevObj = new GPObject(gameObject);
				
				currentColor = Color.white;
				colorPicker.GetComponent<ColorPickerHandler>().colorObject(currentColor);
				
				
				GPObject newObj = new GPObject(gameObject);
				THistory.Instance.addAction(new TChangeColorAction(prevObj,newObj));
			}else{
				colorIcon.SetActive(false);
				colorPicker.SetActive(true);
				pickerActiveTime = Time.time;
			}
		}
	}
	
	public override void FixedUpdate(){
		if(Time.time - pickerActiveTime > 3 && !isFixed){
			colorPicker.SetActive(false);	
			colorIcon.SetActive(true);
		}
	}
	
	public override List<LightHitInfo> getNextLightRay(LightHitInfo hitInfo){
		List<LightHitInfo> newRays = new List<LightHitInfo>();
		
		hitInfo.Direction = Vector3.zero;	
		
		newRays.Add(hitInfo);
		return newRays;	
	}

}
